@extends('backend.layouts.app')

@section('title', $title = '投注记录查询')

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">集成系统</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{$title}}</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" method="GET"
              action="{{ route('player_bet_flow.index') }}">
            {{ csrf_field() }}
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">投注时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="bet_start_date" name="bet_start_date"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('bet_start_date',$params['bet_start_date'])}}">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="bet_end_date" name="bet_end_date"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('bet_end_date',$params['bet_end_date'])}}">
                    </div>
                </div>
                <div class=" layui-inline">
                    <label class="layui-form-label">玩家名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" width="200" autocomplete="off" placeholder="请输入玩家名称"
                               class="layui-input" value="{{old('username',$params['username'])}}">
                    </div>
                </div>
                @if(\Auth::user()->type!=2)
                    <div class=" layui-inline">
                        <label class="layui-form-label">网站名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="site_username" width="200" autocomplete="off"
                                   placeholder="请输入网站名称"
                                   class="layui-input" value="{{old('site_username',$params['site_username'])}}">
                        </div>
                    </div>
                @endif

                <div class=" layui-inline">
                    <label class="layui-form-label">平台编号</label>
                    <div class="layui-input-block">
                        <select name="main_game_plat_code" lay-verify="" lay-search="">
                            <option value="">请选择平台编号</option>
                            @foreach($plats as $plat)
                                <option value={{$plat->main_game_plat_code}} @if($params['main_game_plat_code']===$plat->main_game_plat_code) selected @endif>{{$plat->main_game_plat_name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>

            <div class=" layui-inline">
                <div class="layui-inline">
                    <label class="layui-form-label">平台订单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="game_flow_code" width="200" autocomplete="off"
                               placeholder="请输入平台订单号"
                               class="layui-input" value="{{old('game_flow_code',$params['game_flow_code'])}}">
                    </div>
                </div>
                <button class=" layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>

        </form>

        <div class="layui-form-item">
            @if(\Auth::user()->can('manage_player_bet_flow_manager'))
            <div class="layui-inline demoTable" style="float: left">
                <a href="{{ route('player_bet_flow.create') }}" class="layui-btn" style="float: left">添加</a>
            </div>
            @endif
            <div class="layui-inline" style="float: right">

                <button type="button" class="layui-btn" id="generate-excel">
                    将表格转换为Excel
                </button>
            </div>
        </div>

        <div class="layui-form">

            @if($playerBetFlows->count())
                <table class="layui-table" id="myTable"
                       lay-data="{id:'DeleteTable',totalRow:true,limit:{{$limit+1}}}">
                    <thead>
                    <tr>
                        <th lay-data="{type:'checkbox', fixed: 'left'}">#</th>
                        <th lay-data="{field:'id', width:80, sort: true}">#</th>
                        <th lay-data="{field:'username',  sort: true}">玩家名称</th>
                        <th lay-data="{field:'site_username', width:100,  sort: true}">网站名称</th>
                        <th lay-data="{field:'game_name',  sort: true}">游戏名称</th>
                        <th lay-data="{field:'main_game_plat_code', width:100,  sort: true}">平台编号</th>
                        <th lay-data="{field:'game_flow_code',  sort: true}">平台记录单号</th>
                        <th lay-data="{field:'bet_amount',  width:100, sort: true}">投注金额</th>
                        <th lay-data="{field:'available_bet_amount',width:100,  sort: true}">有效投注</th>
                        <th lay-data="{field:'company_payout_amount',width:100,  sort: true}">公司派彩</th>
                        <th lay-data="{field:'company_win_amount',  sort: true,}">公司输赢</th>
                        <th lay-data="{field:'bet_flow_available',width:100,  sort: true}">是否有效</th>
                        <th lay-data="{field:'status', width:100, sort: true}">是否可用</th>
                        <th lay-data="{field:'bet_time', width:170, sort: true}">投注时间</th>
                        @if(\Auth::user()->can('manage_player_bet_flow_manager'))
                            <th lay-data="{field:'cz',  sort: true}">操作</th>
                        @endif
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($playerBetFlows as $index => $playerBetFlow)
                        <tr>
                            <td></td>
                            <td>{{ $playerBetFlow->id }}</td>
                            <td>{{ $playerBetFlow->username  }}</td>
                            <td>{{ $playerBetFlow->site_username  }}</td>
                            <td>{{ $playerBetFlow->game()->cn_name??$playerBetFlow->game_code  }}</td>
                            <td>{{ $playerBetFlow->main_game_plat_code  }}</td>
                            <td>{{ $playerBetFlow->game_flow_code  }}</td>
                            <td>{{ $playerBetFlow->bet_amount  }}</td>
                            <td>{{ $playerBetFlow->available_bet_amount  }}</td>
                            <td>{{ $playerBetFlow->company_payout_amount  }}</td>
                            @if($playerBetFlow->company_win_amount>0)
                                <td><div class="layui-bg-green" style="text-align: center">{{$playerBetFlow->company_win_amount}}</div></td>
                            @elseif($playerBetFlow->company_win_amount <0)
                                <td><div class="layui-bg-red" style="text-align: center">{{$playerBetFlow->company_win_amount}}</div></td>
                            @else
                                <td><div class="layui-bg-orange" style="text-align: center">{{$playerBetFlow->company_win_amount}}</div></td>
                            @endif
                            <td>{{ $playerBetFlow->bet_flow_available?'是':'否'  }}</td>
                            <td>{{ $playerBetFlow->status?'是':'否'  }}</td>
                            <td>{{ $playerBetFlow->bet_time  }}</td>
                            @if(\Auth::user()->can('manage_player_bet_flow_manager'))
                                <td>
                                    <a href="{{ route('player_bet_flow.edit', $playerBetFlow->id) }}"
                                       class="layui-btn layui-btn-sm layui-btn-normal">编辑</a>
                                </td>
                            @endif
                        </tr>
                    @endforeach
                    <tr>
                        <td></td>
                        <td>总合计：</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>{{$sumParams['bet_amount']}}</td>
                        <td>{{$sumParams['available_bet_amount']}}</td>
                        <td>{{$sumParams['company_payout_amount']}}</td>
                        <td>{{$sumParams['company_win_amount']}}</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    </tbody>
                </table>
                <div id="paginate-render"></div>
            @else
                <br/>
                <blockquote class="layui-elem-quote">暂无数据!</blockquote>
            @endif

        </div>
    </div>

@endsection

@section('scripts')
    @include('backend.layouts._paginate',[ 'count' => $playerBetFlows->total(), 'delBatchUrl'=>'','limit'=>$limit])


    <script type="text/javascript" src="/js/external/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="/js/external/jszip.js"></script>
    <script type="text/javascript" src="/js/external/FileSaver.js"></script>
    <script type="text/javascript" src="/js/scripts/excel-gen.js"></script>

    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#bet_start_date'
                , type: 'datetime'
            });

            laydate.render({
                elem: '#bet_end_date'
                , type: 'datetime'
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            excel = new ExcelGen({
                "src_id": "myTable",
                "show_header": true
            });
            $("#generate-excel").click(function () {
                excel.generate();
            });
        });


    </script>
@endsection
